<?php 
class rss extends control
{
	private $link;
	private $dir;

	public function __construct() {
		parent::__construct();
		$this->link = $this->loadModel('link');
		$this->dir = $this->loadModel('dir');
	}
	
	public function getRssTree() {
		$dir_id = $this->load->input->int('node');
	//	$dir_id = '19';	
		if($dir_id) {
			$cond = array('parent_dir_id'=>$dir_id,'user_id'=>$this->user_id);
			$field = array('dir_id AS id','parent_dir_id','dir_name AS text');
			$dirs = $this->dir->findAll($cond,$field);
			$cond2 = array('dir_id'=>$dir_id,'user_id'=>$this->user_id,'link_type'=>'1');
	   		$field2 = array('link_id AS link_id','link_url AS url','link_name AS text');
			$links = $this->link->findAll($cond2,$field2);
			$rows = $dirs + $links;
			echo json_encode($rows);
		//	print_r($rows);
		}
	}
	
	public function ParseRssUrl12() {
		$url = $this->load->input->validURL('link_url');
		//$url = 'http://news.163.com/special/00011K6L/rss_newstop.xml';
		$this->rss->parse();
		$channel = $this->rss->getChannelInfo();
		$this->link->insertLinkUrl($channel,$url,$this->user_id);
		//print_r($channel);
		//$items = $this->rss->getItems();
		//print_r($items);
	}
	
	public function ParseRssUrl() {
		$link_url = $this->load->input->validURL('link_url');
		$link_url = 'http://www.people.com.cn/rss/sports.xml';
	//	$link_url = 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml';
		
		if($link_url) {
			$rss = $this->loadLib('XML_RSS',$link_url);
			$rss->parse();
			$rows = $rss->getItems();
		//	print_r($rows);
			//echo '{success:true,link_url:'.$link_url.',rows:'.json_encode($rows).'}';
		//	echo '{success:true,link_url:'.$link_url.',rss:'.json_encode($rows).'}';
			echo '{success:true,rss:[{"title":"6","link":"1","description":"BeautyRss","pubdate":"user"}]}';	
		}
	}
}
?>
